﻿namespace DataScripter.Excel.Formulas
{
	public abstract class Formula
	{
		public abstract string Resolve(ICell current);

		public static Formula operator -(Formula ref1, Formula ref2)
		{
			if (ref2 == null)
				return ref1;

			return new Operator(ref1, ref2, "-");
		}
        public static Operator operator -(Formula ref1, int i)
		{
			return new Operator(ref1, i, "-");
		}
        public static Operator operator -(int i, Formula ref2)
		{
			return new Operator(i, ref2, "-");
		}

        public static Operator operator -(Formula formula)
		{
			return new Operator(new Empty(), formula, "-");
		}

        public static Operator operator *(Formula ref1, Formula ref2)
		{
			return new Operator(ref1, ref2, "*");
		}

        public static Operator operator *(Formula ref1, int i)
		{
			return new Operator(ref1, i, "*");
		}

        public static Operator operator *(int i, Formula ref2)
		{
			return new Operator(i, ref2, "*");
		}

		public static Operator operator /(Formula ref1, Formula ref2)
		{
			return new Operator(ref1, ref2, "/");
		}

        public static Operator operator /(int i, Formula ref2)
		{
			return new Operator(i, ref2, "/");
		}
        public static Operator operator /(Formula ref1, int i)
		{
			return new Operator(ref1, i, "/");
		}

		public static Formula operator +(Formula ref1, Formula ref2)
		{
			if (ref2 == null)
				return ref1;

			return new Operator(ref1, ref2, "+");
		}

		public static Operator operator +(int i, Formula ref2)
		{
			return new Operator(i, ref2, "+");
		}

		public static Operator operator +(Formula ref1, int i)
		{
			return new Operator(ref1, i, "+");
		}

		public static Operator operator +(Formula ref1, decimal d)
		{
			return new Operator(ref1, d, "+");
		}

		public static Operator operator <(Formula ref1, Formula ref2)
		{
			return new Operator(ref1, ref2, "<");
		}

		public static Operator operator >(Formula ref1, Formula ref2)
		{
			return new Operator(ref1, ref2, ">");
		}

		public static Operator operator <=(Formula ref1, Formula ref2)
		{
			return new Operator(ref1, ref2, "<=");
		}

		public static Operator operator >=(Formula ref1, Formula ref2)
		{
			return new Operator(ref1, ref2, ">=");
		}

		public static Operator operator &(Formula ref1, Formula ref2)
		{
			return new Operator(ref1, ref2, "&");
		}

        public static Operator operator ^(Formula ref1, Formula ref2)
		{
			return new Operator(ref1, ref2, "^");
		}
        public static Operator operator ^(Formula ref1, int i)
		{
			return new Operator(ref1, i, "^");
		}
        public static Operator operator ^(int i, Formula ref2)
		{
			return new Operator(i, ref2, "^");
		}

		public override string ToString()
		{
			return Resolve(new Cell(null, "A1"));
		}
	}
}